package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;

/**
 * @Author: liangWeiQUQ
 * @Description: TODO
 * @DateTime: 2021/2/26 22:55
 **/
@RestController
@RequestMapping("checkgroup")
@Slf4j
public class CheckGroupController {
    /**
     * @Author: liangWeiQUQ
     * @Date: 23:00 2021/2/26
     * @Parms
     * @ReturnType:
     * @Description: 检查组-分页查询
     */
    @DubboReference
    private CheckGroupService checkGroupService;
    /**
             * @Author: 传闻中的梁大侠
             * @Date: 8:51 2021/3/4
             * @Parms
             * @ReturnType:
             * @Description:
            */

    @GetMapping("findPage")
    public Result findPage(QueryPageBean queryPageBean) {
        log.info("[检查组-分页查询]data:{}", queryPageBean);
        PageResult pageResult = checkGroupService.findPage(queryPageBean);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, pageResult);
    }

    /**
     * @Author: liangWeiQUQ
     * @Date: 23:13 2021/2/26
     * @Parms
     * @ReturnType:
     * @Description: 检查组--查询所有项
     */
    /**
     * @Author: liangWeiQUQ
     * @Date: 23:17 2021/2/26
     * @Parms
     * @ReturnType:
     * @Description: 检查组新增所有项目
     */
    @PostMapping("add")
    public Result add(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        log.info("[检查组-新增数据]checkitemids: {},  checkGroup: {}", checkitemIds, checkGroup);
        checkGroupService.add(checkitemIds, checkGroup);
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
    }

    /**
     * @Author: liangWeiQUQ
     * @Date: 15:05 2021/2/27
     * @Parms
     * @ReturnType:
     * @Description: 检查组-根据id查询检查组
     */
    @GetMapping("findById")
    public Result findById(Integer id) {
        log.info("[检查组-根据id查询检查组] id: {}", id);
        CheckGroup checkGroup = checkGroupService.findById(id);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, checkGroup);
    }

    /**
     * @Author: liangWeiQUQ
     * @Date: 15:05 2021/2/27
     * @Parms [id]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 检查组-根据检查组id查询关联检查项信息
     */
    @GetMapping("findCheckItemIdsById")
    public Result findCheckItemIdsById(Integer id) {
        log.info("[检查组-根据检查组id查询关联检查项信息] id: {}", id);
        List<Integer> checkItemIds = checkGroupService.findCheckItemIdsById(id);
        return new Result(true, MessageConst.QUERY_CHECKITEM_SUCCESS, checkItemIds);
    }

    /**
     * @Author: liangWeiQUQ
     * @Date: 15:05 2021/2/27
     * @Parms [checkitemIds, checkGroup]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 检查组-修改数据
     */
    @PostMapping("edit")
    public Result edit(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        log.info("[检查组-修改数据]checkitemids: {},  checkGroup: {}", checkitemIds, checkGroup);
        checkGroupService.edit(checkitemIds, checkGroup);
        return new Result(true, MessageConst.EDIT_CHECKGROUP_SUCCESS);
    }

    /**
     * @Author: liangWeiQUQ
     * @Date: 17:24 2021/2/27
     * @Parms
     * @ReturnType:
     * @Description: 检查组-根据检查组id删除检查项信息
     */
    @PostMapping("delete")
    public Result delete(Integer id) {
        log.info("[检查组-根据检查组id删除检查项信息] id: {}", id);
        checkGroupService.deleteById(id);
        return new Result(true, MessageConst.DELETE_CHECKITEM_SUCCESS);
    }
    /**
     * @Author: liangWeiQUQ
     * @Date: 17:24 2021/2/27
     * @Parms
     * @ReturnType:
     * @Description: 检查组-查询所有检查组
     */
    @GetMapping("findAll")
    public Result findAll() {
        log.info("[检查组-查询所有检查组");
        List<CheckGroup> checkGroups = checkGroupService.findAll();
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, checkGroups);

    }
}